<?php if (defined("YTDJ") or die()); 

Class AdminController extends Controller {
	
	function admin() {		
		$this->loadTemplate();
		$this->display();
	}
	
	function updateVideos() {
		$db =& DB::getInstance();
		$this->count = $db->select_one("SELECT COUNT(*) FROM video WHERE updatedon IS NULL OR updatedon < CURDATE() - ".Config::getInstance()->renewVideoAfterDays);
		$this->loadTemplate();
		$this->display();
	}
	
	function updateVideo() {
		$db =& DB::getInstance();
		$db->select("SELECT * FROM video WHERE updatedon IS NULL OR updatedon < CURDATE() - ".Config::getInstance()->renewVideoAfterDays." ORDER BY RAND() LIMIT 1");
		$video = $db->get_obj();
		
		if (count($video) > 0) {
			$video = YouTube::getVideo($video[0]->id, true);
			$video->setUpdated();
			echo "<span>$video->id</span>";
			$this->display();
		} else {
			echo "Ready";
		}
	}
}

?>